package com.h3c.nem.controller;

import com.eos.common.constant.StatusCodeEnum;
import com.eos.common.custom.BusinessException;
import com.eos.common.util.Result;
import com.h3c.nem.entity.TbOfferWorkerFeedback;
import com.h3c.nem.service.TbOfferWorkerFeedbackService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;
import java.util.Objects;

/**
 * (TbOfferWorkerFeedback)表控制层
 *
 * @author makejava
 * @since 2022-07-27 14:25:11
 */
@RestController
@RequestMapping("tbOfferWorkerFeedback")
public class TbOfferWorkerFeedbackController {
    /**
     * 服务对象
     */
    @Resource
    private TbOfferWorkerFeedbackService tbOfferWorkerFeedbackService;



    @PostMapping("/submit")
    public Result<String> submitFeedbackProblem(@RequestBody Map<String, String> map){
        String workerId = map.get("workerId");
        String feedback = map.get("feedback");
        if (Objects.nonNull(feedback) && feedback.length() > 0 ) {
            try {
                String result = tbOfferWorkerFeedbackService.submitFeedback(workerId, feedback);
                return new Result(true, StatusCodeEnum.NORMAL);
            } catch (BusinessException e) {
                return new Result(false, StatusCodeEnum.USER_NOT_EXIST);
            }
        }
        return new Result(false, 400, "没有问题描述!");
    }

    /**
     * 分页查询
     *
     * @param tbOfferWorkerFeedback 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<TbOfferWorkerFeedback>> queryByPage(TbOfferWorkerFeedback tbOfferWorkerFeedback, PageRequest pageRequest) {
        return ResponseEntity.ok(this.tbOfferWorkerFeedbackService.queryByPage(tbOfferWorkerFeedback, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TbOfferWorkerFeedback> queryById(@PathVariable("id") String id) {
        return ResponseEntity.ok(this.tbOfferWorkerFeedbackService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tbOfferWorkerFeedback 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<TbOfferWorkerFeedback> add(TbOfferWorkerFeedback tbOfferWorkerFeedback) {
        return ResponseEntity.ok(this.tbOfferWorkerFeedbackService.insert(tbOfferWorkerFeedback));
    }

    /**
     * 编辑数据
     *
     * @param tbOfferWorkerFeedback 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<TbOfferWorkerFeedback> edit(TbOfferWorkerFeedback tbOfferWorkerFeedback) {
        return ResponseEntity.ok(this.tbOfferWorkerFeedbackService.update(tbOfferWorkerFeedback));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(String id) {
        return ResponseEntity.ok(this.tbOfferWorkerFeedbackService.deleteById(id));
    }

}

